﻿<?php
	if(!isset($_REQUEST['id']))
		die('{"error":5,"error_msg":"Parameter missing."}');
	
	require("db_connection.php");

	$sql = "SELECT * FROM greetings WHERE id=".$_REQUEST['id'];
	$result = mysql_query($sql);	
	
	if(!$result)
	{		
		die('{"error":1,"error_msg":"Database Error."}');
		mysql_close($conn);	
	}
	
	if(mysql_num_rows($result) > 0)
	{
		$record =  mysql_fetch_array($result);
		$strGreeting = '{"id":"'.$record['id'].'",';
		$strGreeting.= '"content":"'.$record['content'].'",';
		$strGreeting.= '"sender_id":"'.$record['sender_id'].'",';
		$strGreeting.= '"receivers_id":"'.$record['receivers_id'].'",';
		$strGreeting.= '"sender_name":"'.$record['sender_name'].'",';
		$strGreeting.= '"receivers_name":"'.$record['receivers_name'].'",';
		$strGreeting.= '"sender_photo":"'.$record['sender_photo'].'"}';
		
		echo $strGreeting;
	}else{
		die('{"error":7,"error_msg":"The specified greeting does not exist."}');
	}
	
	mysql_close($conn);
?>